package com.dreammakerteam.frameworkdemo.base.domain;

import com.baomidou.mybatisplus.plugins.Page;

import java.util.List;

/**
 * Created by ty850 on 2017/9/16.
 */
public class DataTablsResult<T> {
    private Integer draw;
    private int recordsTotal;
    private int recordsFiltered;
    private List<T> data;
    private String error;

    public static <T> DataTablsResult<T> valueOf(Page<T> page, int draw) {
        DataTablsResult<T> result = new DataTablsResult<>();
        result.setData(page.getRecords());
        result.setRecordsFiltered(page.getTotal());
        result.setRecordsTotal(page.getTotal());
        result.setDraw(draw);
        return result;
    }

    public int getDraw() {
        return draw;
    }

    public DataTablsResult setDraw(int draw) {
        this.draw = draw;
        return this;
    }

    public int getRecordsTotal() {
        return recordsTotal;
    }

    public DataTablsResult setRecordsTotal(int recordsTotal) {
        this.recordsTotal = recordsTotal;
        return this;
    }

    public int getRecordsFiltered() {
        return recordsFiltered;
    }

    public DataTablsResult setRecordsFiltered(int recordsFiltered) {
        this.recordsFiltered = recordsFiltered;
        return this;
    }

    public List<T> getData() {
        return data;
    }

    public DataTablsResult setData(List<T> data) {
        this.data = data;
        return this;
    }

    public String getError() {
        return error;
    }

    public DataTablsResult setError(String error) {
        this.error = error;
        return this;
    }
}
